import React from 'react';
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
import 'antd/dist/reset.css';
import './App.css';

// 页面组件
import LoginPage from './pages/LoginPage';
import DashboardContent from './pages/DashboardContent';
import FocusMode from './pages/FocusMode';
import StudyPlan from './pages/StudyPlan';
import Friends from './pages/Friends';
import Chat from './pages/Chat';
import AIChat from './pages/AIChat';
import CloudStorage from './pages/CloudStorage';
import CareerPlan from './pages/CareerPlan';
import KnowledgeGraph from './pages/KnowledgeGraph';
import Profile from './pages/Profile';
import Settings from './pages/Settings';
import Notification from './pages/Notification';
import NotificationDetail from './pages/NotificationDetail';
import SharePage from './pages/SharePage';

// 组件
import Layout from './components/Layout';
import ProtectedRoute from './components/ProtectedRoute';
import SimplePagePreloader from './components/SimplePagePreloader';
import BackgroundTimerProvider from './components/BackgroundTimerManager';
import BackgroundTimerIndicator from './components/BackgroundTimerIndicator';
import DraggableIcon from './components/DraggableIcon';

// 上下文
import { AuthProvider } from './store/AuthContext';
import { ThemeProvider } from './store/ThemeContext';

function App() {

  return (
    <ThemeProvider>
      <AuthProvider>
        <SimplePagePreloader>
          <Router>
            <BackgroundTimerProvider>
              <div className="App">
                <Routes>
                  {/* 登录页面 */}
                  <Route path="/login" element={<LoginPage />} />
                  
                  {/* 分享页面 - 不需要认证 */}
                  <Route path="/share/:shareToken" element={<SharePage />} />
                  
                  {/* 受保护的路由 - 使用传统布局 */}
                  <Route path="/" element={<ProtectedRoute><Layout /></ProtectedRoute>}>
                    <Route index element={<Navigate to="/dashboard" replace />} />
                    <Route path="dashboard" element={<DashboardContent />} />
                    <Route path="focus" element={<FocusMode />} />
                    <Route path="study-plan" element={<StudyPlan />} />
                    <Route path="friends" element={<Friends />} />
                    <Route path="chat" element={<Chat />} />
                    <Route path="ai-chat" element={<AIChat />} />
                    <Route path="cloud-storage" element={<CloudStorage />} />
                    <Route path="career-plan" element={<CareerPlan />} />
                    <Route path="knowledge-graph" element={<KnowledgeGraph />} />
                    <Route path="profile" element={<Profile />} />
                    <Route path="settings" element={<Settings />} />
                    <Route path="notification" element={<Notification />} />
                    <Route path="notifications/:id" element={<NotificationDetail />} />
                  </Route>
                </Routes>
                
                {/* 后台计时器指示器 */}
                <BackgroundTimerIndicator />
                
                {/* 可拖动图标 */}
                <DraggableIcon />
              </div>
            </BackgroundTimerProvider>
          </Router>
        </SimplePagePreloader>
      </AuthProvider>
    </ThemeProvider>
  );
}

export default App;